<%--
 *  File:    SystemMenuConfigNew.jsp
 *  @Author: Michael Zhao 
 *  Date:    2002/11/20
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>


<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<%
  
  String strModuleName = "IMG";    
  String privilegeCode = "Z0812";
  String contextPath = request.getContextPath();
%>


<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>

<html>
<head>
<title></title>
<PageFlow:CheckPageFlow pageName="systemmenunew"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
<SCRIPT language=JavaScript1.2 src="../css/menu.js"></SCRIPT>
<script language="JavaScript" src="../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../js/ScriptLib.js"></script>
<iframe name="reloadHandler" style="display:none" ></iframe>
<%
  
    int grade = -1;
	Integer nSortNo = null;
	Integer app = null;
	Integer nStatus = null;
	String strPrivilegeCode = "";
	String strPrivilegeType = "";
    String strUrl = "";
	String parentmenucode = "";
	String strModule = "";
	if(pageContext.getAttribute("app")!=null)
	{
	 app = (Integer)pageContext.getAttribute("app");
	}
    if(pageContext.getAttribute("parentmenucode")!=null)
	{
	 parentmenucode = (String)pageContext.getAttribute("parentmenucode");
	}
	HashMap appinfo = (HashMap)pageContext.getAttribute("appinfo");
	
	if(appinfo == null)
	{
		appinfo = new HashMap();
	}

	HashMap appinfo1 = (HashMap)pageContext.getAttribute("appinfo1");
	
	if(appinfo1 == null)
	{
		appinfo1 = new HashMap();
	}

	HashMap selectmenu = (HashMap)pageContext.getAttribute("selectmenu");
	
	if(selectmenu == null)
	{
		selectmenu = new HashMap();
	}
    if(!selectmenu.isEmpty())
	{
	    grade = ((Integer)selectmenu.get("grade")).intValue();
        grade = grade + 1;
	}
	Vector allmenutype = (Vector)pageContext.getAttribute("allmenutype");
    if(allmenutype == null)
	{
		allmenutype = new Vector();
	}
    else
	{
		HashMap temp = new HashMap(); 
		for(int p=0; p<allmenutype.size(); p++)
		{
			if(((String)(((HashMap)(allmenutype.elementAt(p))).get("privilegetype"))).equalsIgnoreCase("M"))
			{
				temp = (HashMap)(allmenutype.elementAt(p));
				allmenutype.remove(p);
				break;
			}
		}
        allmenutype.add(0,temp);
	}
	Vector allstatus = (Vector)pageContext.getAttribute("allstatus");
    if(allstatus == null)
	{
		allstatus = new Vector();
	}
     else
	{
		HashMap temp = new HashMap(); 
		for(int p=0; p<allstatus.size(); p++)
		{
			if(((((HashMap)(allstatus.elementAt(p))).get("value")).toString()).equalsIgnoreCase("41"))
			{
				temp = (HashMap)(allstatus.elementAt(p));
				allstatus.remove(p);
				break;
			}
		}
        allstatus.add(0,temp);
	}

	HashMap apphash = (HashMap)pageContext.getAttribute("apphash");
	
	if(apphash == null)
	{
		apphash = new HashMap();
	}

   if(request.getParameter("privilegecode")!= null)
   {
	strPrivilegeCode = (String)request.getParameter("privilegecode");
   }

   if(request.getParameter("privilegetype")!= null)
   {
	strPrivilegeType = (String)request.getParameter("privilegetype");
	pageContext.setAttribute("privilegetype",strPrivilegeType);
   }

   if(request.getParameter("url")!= null)
   {
	strUrl = (String)request.getParameter("url");
   }
   
   if(request.getParameter("module")!= null)
   {
	strModule = (String)request.getParameter("module");
   }
   if(selectmenu.isEmpty())
   {
   if(request.getParameter("sortno")!= null&&(!request.getParameter("sortno").equalsIgnoreCase("")))
   {
	 System.out.println("sortno is "+request.getParameter("sortno"));
	 nSortNo = Integer.valueOf((request.getParameter("sortno")).toString());
	
   }
   if(request.getParameter("status")!= null&&(!request.getParameter("status").equalsIgnoreCase("")))
   {
	 System.out.println("status is "+request.getParameter("status"));
	 nStatus = Integer.valueOf((request.getParameter("status")).toString());
	 pageContext.setAttribute("status",nStatus);
   }
   }
   HashMap emptyHash = new HashMap();

%>
<script>

  function page_selectmenu()
  {
	  
    var strurl="../img/MenuSelect.jsp?<%= OvalTools.randomURL() %>&app="+"<%=JspHelper.filterNull( app)%>";
	var strstatus=" height=320, width=520,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no";
    if(popwindow!=null)
        popwindow.close();
    popwindow = window.open(strurl,"newwindow" ,strstatus);
  }
  function page_setMenu(id, code, name, grade,isbottom,module)
{
   var frm = document.cform; 
   frm.parentprivid.value = id;
   frm.grade1.value = grade;
   frm.grade.value = Number(frm.grade1.value) + Number(1);
   frm.parentmenuname.value = name;  
   frm.parentmenucode.value = code;
   frm.module.value = module;
   if(frm.privilegecode.value=='')
   	 frm.privilegecode.value = code;
   frm.isbottom1.value = isbottom;
   if(popwindow!=null)
        popwindow.close();
}


function reload()
{
	var parentmenucode= document.cform.parentmenucode.value;

  cform.parentmenuname.value='';

  page_handleRequest('<%=contextPath%>',cform);
}
function page_handleResponse()
{
  cform.parentmenucode.value = getResponseData("privilegecode");
  cform.parentmenuname.value = getResponseData("prn");
  cform.parentprivid.value = getResponseData("privilegeid");
  cform.grade.value = Number(getResponseData("grade"))+ Number(1);
  cform.isbottom1.value = getResponseData("isbottom");
  
}
function page_save()
{
	 if(document.cform.privilegecode.value == -1||document.cform.privilegecode.value == "")
	{
       alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_MenuCode",false)) %>");
       return;
	}
     if(document.cform.privilegetype.value == -1||document.cform.privilegetype.value == "")
	{
       alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_MenuType",false)) %>");
       return;
	}
	 if(document.cform.sortno.value == -1||document.cform.sortno.value == "")
	{
       alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_SortNo",false)) %>");
       return;
	}
	if(document.cform.url.value == -1||document.cform.url.value == "")
	{
       alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_Url",false)) %>");
       return;
	}
	if(document.cform.prn0.value == -1||document.cform.prn0.value == "")
	{
       alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_MenuName",false)) %>");
       return;
	}
    if(document.cform.module.value == -1||document.cform.module.value == "")
	{
       alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_BelongModule",false)) %>");
       return;
	}
	if(document.cform.status.value == -1||document.cform.status.value == "")
	{
       alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_Status",false)) %>");
       return;
	}
    if(document.cform.parentmenucode.value == -1||document.cform.parentmenucode.value == "")
	{
		var fisrtCharactors = "<%=JspHelper.filterNull( (String)apphash.get("firstcharactors"))%>";
		var menucode = document.cform.privilegecode.value;
		if(fisrtCharactors.search(menucode.charAt(0))== -1)
		{
		 alert("<%= message.getMessageDesc("FIRST_VALUE_MUST_IN_FIRSTCHARACTORS",label.getLabelName("L_MenuCode",false)) %>");
		 return;
		}
		
	 }
/*	 else
	{
		 var parentmenucode = document.cform.parentmenucode.value;
		 var menucode = document.cform.privilegecode.value;
		 if(menucode.search(parentmenucode)== -1)
		{
           alert("<%= message.getMessageDesc("MENUCODE_MUST_INCLUDE_PARENTCODE",label.getLabelName("L_MenuCode",false)) %>");
		   return;
		}

	}*/
	MLCSTransform(cform);
	if(!checkForm(document.cform))return;
	cform.actionname.value = "save";
  	cform.target = "_parent";
  	isRunning = true;
  	cform.submit();
}

</script>


</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
  <form name="cform" method="post" action="../Dispatcher">
    <input type="hidden" name="pagename" value="systemmenunew">
	<input type="hidden" name="actionname">
	
	<input type="hidden" name="numrows" value="2"> 
	
    <input type="hidden" name="app" value="<%=JspHelper.filterNull( apphash.get("appid"))%>">
	<input type="hidden" name="appcode" value="<%=JspHelper.filterNull( apphash.get("appcode"))%>">
	
	<input type="hidden" name="languagecode" value="<%= strLanguageCode %>">
	<input type="hidden" name="datelastupdated" value="<%=JspHelper.filterNull( new java.sql.Date(new java.util.Date().getTime()) )%>">
	<%if(selectmenu.isEmpty()) {%>
	 <input type="hidden" name="parentprivid"> 
	 <input type="hidden" name="grade">
     <input type="hidden" name="grade1">
	 <input type="hidden" name="isbottom" value="Y">
	 <input type="hidden" name="isbottom1">
    <%} else {%>
	  <input type="hidden" name="parentprivid" value="<%=JspHelper.filterNull( selectmenu.get("privilegeid"))%>">
	  <input type="hidden" name="grade" value="<%=JspHelper.filterNull( new Integer(grade))%>">
	  <input type="hidden" name="isbottom" value="Y">
      <input type="hidden" name="isbottom1" value="<%=JspHelper.filterNull( selectmenu.get("isbottom"))%>">
	<%}%>
	  <input type="hidden" name="schema" value="ovprivilegesummary">
    <input type="hidden" name="qlname" value="selectbyparentmenucode">

    <tr> 
    <td valign="top"> 
      <table width="100%" cellspacing="0" cellpadding="0">
	  <tr> 
          <td colspan="2"><img src="../images/<%= strLanguageCode %>/quote.gif" width="16" height="11"> 
            <%= label.getLabelName("L_MenuInformation") + label.getLabelName("L_Colon") %></td>
        </tr>
      </table>
	   <table border="1" cellpadding="2" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%">
        <tr> 
          <td width="92" class="need"><%= label.getLabelName("L_MenuCode") + label.getLabelName("L_Colon") %></td>
          <td> 
           <% if(selectmenu.isEmpty()) {%>
		   <input type="text" name="privilegecode" size="18" value="<%=JspHelper.filterNull( strPrivilegeCode)%>">
		   <%} else {%>
           <input type="text" name="privilegecode" size="18" value="<%=JspHelper.filterNull( selectmenu.get("privilegecode"))%>">
		   <%}%>
		  </td>
        </tr>
		<tr>
		<td class="need" width="92"><%= label.getLabelName("L_MenuType") + label.getLabelName("L_Colon") %></td>
		<td><custom:select optionsName="allmenutype" optionValueKey="privilegetype" optionInnerTextKey="privilegetype" name="appinfo1" property="privilegetype" /></td>
		</tr>
		<tr> 
          <td class="need" width="92"><%= label.getLabelName("L_SortNo") + label.getLabelName("L_Colon") %></td>
          <td> 
            <%if(nSortNo != null) {%>
            <input type="text" name="sortno" size="18" value="<%=JspHelper.filterNull( nSortNo)%>">
            <%} else {%>
            <custom:text name="emptyhash" property="sortno" size="18" dataType="integer" module="IMG" label="L_SortNo"/>
            <%}%>
          </td>
        </tr>
		<tr> 
          <td class="need" width="92"><%= label.getLabelName("L_Url") + label.getLabelName("L_Colon") %></td>
          <td> 
            <input type="text" name="url" size="80" value="<%=JspHelper.filterNull( strUrl)%>">
          </td>
        </tr>
		<tr> 
          <td class="need" width="92"><%= label.getLabelName("L_MenuName") + label.getLabelName("L_Colon") %> </td>
          <td> 
            <custom:text name="menuinfo" property="prn" size="18" command="notnull" module="IMG" label="L_MenuName" needMLC="true" isFirstMLC="true" multiLangType="prn" entityId="privilegeid" contentId="privilegelangid" colIndex="0"/>
			<a onclick='popup("../common/Lang.jsp?<%= OvalTools.randomURL() %>&form=cform&module=IMG&mlctype=L_MenuName&nativelanguage=need&schema=ovprivilegelang&qlname=selectbyid&entityid=<custom:write name="menu" property="privilegeid"/>&entitytype=prn&contentid=privilegelangid&colindex=0", "newwindow", "height=250, width=320,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no");'><custom:button type="3" label="L_Ln" imgsrc="ln.gif" border="0"/></a>
          </td>
        </tr>
		 <tr> 
          <td class="td-text" width="92"><%= label.getLabelName("L_ParentMenu") + label.getLabelName("L_Colon") %></td>
          <td> 
            <input type="text" name="parentmenucode" size="18" value="<%=JspHelper.filterNull( parentmenucode)%>" onchange="javascript:reload()">
            <a onclick="javascript:page_selectmenu();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a> 
            <input type="text" name="parentmenuname" size="30" value="<%=JspHelper.filterNull( selectmenu.get("prn"))%>" readonly>
          </td>
        </tr>
        <tr> 
          <td class="need" width="92"><%= label.getLabelName("L_BelongModule") + label.getLabelName("L_Colon") %></td>
          <td> 
            <% if(selectmenu.isEmpty()) {%>
			<input type="text" name="module" size="18" value="<%=JspHelper.filterNull( strModule)%>">
			<% } else {%>
            <input type="text" name="module" size="18" value="<%=JspHelper.filterNull( selectmenu.get("module"))%>">
			<%}%>
          </td>
        </tr>
        <tr>
		    <td class="need" width="92"><%= label.getLabelName("L_Status") + label.getLabelName("L_Colon") %></td>
		    <td><custom:select optionsName="allstatus" optionValueKey="value" optionInnerTextKey="valuename" name="appinfo1" property="status" /></td>
		</tr>
		<table width="100%" cellspacing="0" cellpadding="0"> 
   <tr> 
    <td class="summary_top" ></td>
  </tr>
  <tr> 
    <td class="td_center"><a onclick="page_save()"><custom:button type="1" label="L_Save" imgsrc="save.gif" border="0" style="width:60"/></a></td>
  </tr>
  </table>
  </table>
   </td>
   </tr>
</form>
</table>
<%
    Vector selecterror =(Vector)pageContext.getAttribute("selecterror");
    if(selecterror!=null && selecterror.size()>0)
    {
        //cat.debug("errorcode is:"+errorcode);
        for(int errorindex=0;errorindex<selecterror.size();errorindex++)
        {
            HashMap hmErrorcode=(HashMap)selecterror.elementAt(errorindex);
            if(hmErrorcode==null)
                hmErrorcode=new HashMap();
            if(hmErrorcode.get("messagecode")!=null && ((String)hmErrorcode.get("messagecode")).equalsIgnoreCase("U_SEL_01") && ((String)hmErrorcode.get("t1")).equalsIgnoreCase("ovprivilegesummary"))
            {
                out.print("<script language='javascript'>alert('"+message.getMessageDesc(hmErrorcode)+"');</script>");
                break;
            }
            
        }
    }

%>
</body>
</html>


